using System.IO;
using SmartBoard.BackGround.Data;
using SmartBoard.Core.Serialization;

namespace SmartBoard.Background.Serialization
{
    internal class V11SerializationStrategy:ISerializationStrategy
    {
        public void Serialize(Stream stream, object obj)
        {
            var data = (V10BackgroundData) obj;
            stream.WriteByte(data.Version);
            stream.WriteByte(data.A);
            stream.WriteByte(data.R);
            stream.WriteByte(data.G);
            stream.WriteByte(data.B);
        }

        public object Deserialize(Stream stream)
        {
            var version = (DataVersion)stream.ReadByte();
            if (version == DataVersion.V10)
            {
                var data = new V10BackgroundData
                               {
                                   A = (byte) stream.ReadByte(), 
                                   R = (byte) stream.ReadByte(), 
                                   G = (byte) stream.ReadByte(), 
                                   B = (byte) stream.ReadByte()
                               };
                return data;
            }
            return null;
        }
    }
}